Imports Microsoft.VisualBasic
Imports sk.DAL

Public Class CommentObj
    Inherits BizObject

    Sub New(ByVal ID As Integer, ByVal userID As String, ByVal commDate As Date, ByVal text As String, ByVal approved As Boolean, ByVal articleID As Integer)
        _CommentID = ID
        _UserID = userID
        _Date = commDate
        _Text = text
        _Approved = approved
        _ArticleID = articleID
    End Sub

    Sub New()

    End Sub
    Private _CommentID As Integer
    Public Property CommentID() As Integer
        Get
            Return _CommentID
        End Get
        Set(ByVal value As Integer)
            _CommentID = value
        End Set
    End Property


    Private _UserID As String
    Public Property UserID() As String
        Get
            Return _UserID
        End Get
        Set(ByVal value As String)
            _UserID = value
        End Set
    End Property


    Private _Date As Date
    Public Property CommDate() As Date
        Get
            Return _Date
        End Get
        Set(ByVal value As Date)
            _Date = value
        End Set
    End Property


    Private _Text As String
    Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property


    Private _Approved As Boolean
    Public Property Approved() As Boolean
        Get
            Return _Approved
        End Get
        Set(ByVal value As Boolean)
            _Approved = value
        End Set
    End Property


    Private _ArticleID As Integer
    Public Property ArticleID() As Integer
        Get
            Return _ArticleID
        End Get
        Set(ByVal value As Integer)
            _ArticleID = value
        End Set
    End Property
    Public Function ChangeCommentApproval(ByVal CommentID As Integer, ByVal status As Boolean) As Boolean
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            provider.ChangeCommentApproval(CommentID, status)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function CreateComment(ByVal Cmt As CommentObj) As Boolean
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim comment As New Comment

            comment.CommentID = Cmt.CommentID
            comment.Approved = True
            comment.ArticleID = Cmt.ArticleID
            comment.CommDate = Cmt.CommDate
            comment.Text = Cmt.Text
            comment.UserID = Cmt.UserID

            provider.CreateComment(comment)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function DeleteComment(ByVal CmtID As Integer) As Boolean
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            provider.DeleteComment(CmtID)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function GetAllComments() As System.Collections.Generic.List(Of CommentObj)
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim objList As New Generic.List(Of CommentObj)
            Dim comList As Generic.List(Of Comment)
            Dim c As Comment
            comList = provider.GetAllComments()
            For Each c In comList
                objList.Add(New CommentObj(c.CommentID, c.UserID, c.CommDate, c.Text, c.Approved, c.ArticleID))
            Next
            Return objList
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of CommentObj)
        End Try
    End Function

    Public Function GetCommentByID(ByVal CmtID As Integer) As CommentObj
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim c As Comment = provider.GetCommentByID(CmtID)
            Return New CommentObj(c.CommentID, c.UserID, c.CommDate, c.Text, c.Approved, c.ArticleID)

        Catch ex As Exception
            Return New CommentObj
        End Try
    End Function

    Public Function GetCommentsByUserID(ByVal UserID As String) As System.Collections.Generic.List(Of CommentObj)
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim objList As New Generic.List(Of CommentObj)
            Dim comList As Generic.List(Of Comment)
            Dim c As Comment
            comList = provider.GetAllComments()
            For Each c In comList
                objList.Add(New CommentObj(c.CommentID, c.UserID, c.CommDate, c.Text, c.Approved, c.ArticleID))
            Next
            Return objList
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of CommentObj)
        End Try
    End Function

    Public Function GetCommentsForArticle(ByVal ArticleID As Integer) As System.Collections.Generic.List(Of CommentObj)
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim objList As New Generic.List(Of CommentObj)
            Dim comList As Generic.List(Of Comment)
            Dim c As Comment
            comList = provider.GetCommentsForArticle(ArticleID)
            For Each c In comList
                objList.Add(New CommentObj(c.CommentID, c.UserID, c.CommDate, c.Text, c.Approved, c.ArticleID))
            Next
            Return objList

        Catch ex As Exception
            Return New System.Collections.Generic.List(Of CommentObj)
        End Try
    End Function


    Public Function GetApprovedCommentsForArticle(ByVal ArticleID As Integer) As System.Collections.Generic.List(Of CommentObj)
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim objList As New Generic.List(Of CommentObj)
            Dim comList As Generic.List(Of Comment)
            Dim c As Comment
            comList = provider.GetApprovedCommentsForArticle(ArticleID)
            For Each c In comList
                objList.Add(New CommentObj(c.CommentID, c.UserID, c.CommDate, c.Text, c.Approved, c.ArticleID))
            Next
            Return objList

        Catch ex As Exception
            Return New System.Collections.Generic.List(Of CommentObj)
        End Try
    End Function

    Public Function GetCommentsOnDate(ByVal CommentDate As Date) As System.Collections.Generic.List(Of CommentObj)
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim objList As New Generic.List(Of CommentObj)
            Dim comList As Generic.List(Of Comment)
            Dim c As Comment
            comList = provider.GetCommentsOnDate(CommentDate)
            For Each c In comList
                objList.Add(New CommentObj(c.CommentID, c.UserID, c.CommDate, c.Text, c.Approved, c.ArticleID))
            Next
            Return objList

        Catch ex As Exception
            Return New System.Collections.Generic.List(Of CommentObj)
        End Try
    End Function

    Public Function GetUserCommentsForArticle(ByVal userID As String, ByVal ArticleID As Integer) As System.Collections.Generic.List(Of CommentObj)
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim objList As New Generic.List(Of CommentObj)
            Dim comList As Generic.List(Of Comment)
            Dim c As Comment
            comList = provider.GetUserCommentsForArticle(userID, ArticleID)
            For Each c In comList
                objList.Add(New CommentObj(c.CommentID, c.UserID, c.CommDate, c.Text, c.Approved, c.ArticleID))
            Next
            Return objList

        Catch ex As Exception
            Return New System.Collections.Generic.List(Of CommentObj)
        End Try
    End Function

    Public Function UpdateComment(ByVal Cmt As CommentObj) As Boolean
        Try
            Dim provider As CommentProvider
            provider = CommentProvider.Instance
            Dim comment As New Comment

            comment.CommentID = Cmt.CommentID
            comment.Approved = Cmt.ArticleID
            comment.ArticleID = Cmt.ArticleID
            comment.CommDate = Cmt.CommDate
            comment.Text = Cmt.Text
            comment.UserID = Cmt.UserID

            provider.CreateComment(comment)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function GetNextID() As Integer

        Dim provider As CommentProvider
        provider = CommentProvider.Instance
        Return provider.GetNextID
    End Function


End Class